<?php
namespace Controller;
use Kuyuan\WqCore\controller\Controller;
use Model\FormModel;

/**
 * 万能表单
 * Class Enter
 * @package Controller
 */
class Form extends Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 添加编辑表单
     * @param array $_data 数据
     * @param int $_form_id 表单id
     * @return mixed
     */
    public function edit(Array $_data,$_form_id = 0)
    {
        if($_form_id) {
            if(!FormModel::where("id",$_form_id)->update($_data)) {
                return false;
            }
        } else {
            $_data["uniacid"] = $this->_uniacid;
            $_data["uid"] = $this->_uid;
            $_form_id = FormModel::createId($_data);
        }
        return $_form_id;
    }

    /**
     * 获取用户万能表单列表
     * @param array $_limit
     * @param int $_uid
     * @return FormModel
     */
    public function getUserAll(Array $_limit,$_uid = 0)
    {
        if(!$_uid) $_uid = $this->_uid;
        $FormModel = FormModel::where("uniacid",$this->_uniacid)
            ->where("uid",$_uid)
            ->where("status","!=",9)
            ->limit($_limit[0],$_limit[1])
            ->order("id","desc")
            ->cache(!KUYUAN_DEBUG);
        return $FormModel->select();
    }

    /**
     * 获取一个表单信息
     * @param $_form_id
     * @return FormModel
     */
    public function get($_form_id)
    {
        return FormModel::where("id",$_form_id)
            ->cache(!KUYUAN_DEBUG)
            ->find();
    }

    /**
     * 删除表单
     * @param $_form_id
     * @return mixed
     */
    public function del($_form_id)
    {
        return FormModel::where("id",$_form_id)
            ->delete();
    }
}